package com.ellwood.copyright.common.core.utils.excel;

import com.ellwood.copyright.common.core.constant.FieldConverter;
import com.ellwood.copyright.common.core.enums.EnumConverter;

/**
 * @ProjectName: ell-copyright-pro
 * @PackageName: com.ellwood.copyright.common.core.utils.excel
 * @ClassName: FieldConverterUtil
 * @Description: // FieldConverterUtil 是一个通用的字段转换器，接收 EnumConverter 枚举并进行转换。
 * @Author: Ellwood
 * @CreateDate: 2024/12/23 - 14:18
 * @Version: V1.0.0
 */
public class FieldConverterUtil implements FieldConverter<Object> {

    private final EnumConverter enumType;

    public FieldConverterUtil(EnumConverter enumType) {
        this.enumType = enumType;
    }

    @Override
    public Object convert(Object value) {
        // 如果值是字符串类型，并且需要根据枚举类型转换
        if (value instanceof String) {
            return enumType.convert((String) value);  // 从String转换到对应的枚举值
        }
        return value;
    }
}
